<?php

namespace App\Service\Kms\Common;

use App\Remote\AMap\AMapPlaceRemote;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;

class WeatherService
{
    /**
     * @param string $long
     * @param string $lat
     * @return array|mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function getWeatherInfo(string $long, string $lat)
    {
        $reGeo       = AMapPlaceRemote::reGeo($long, $lat);
        $adCode      = attributeGet($reGeo, "regeocode.addressComponent.adcode", 0);
        $weatherInfo = [];
        if ($adCode) {
            $weatherInfo = attributeGet(AMapPlaceRemote::weatherInfo($adCode), "lives.0", []);
        }
        return $weatherInfo;
    }
}
